<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>查看异常节点</title>
    <script src="../../../static/kaige/js/szload.js"></script>
</head>

<body>
    <div class="kaige-body kaige-btn-radius">
        <table class="layui-hide" id="pageTable" lay-filter="pageTable"></table>
    </div>
    <script>
        load_init_js(function () {
            layui.use(['table', 'form', 'layer', 'laydate', 'element'], function () {
                var layer = layui.layer, table = layui.table, form = layui.form, laydate = layui.laydate, element = layui.element;
                //执行渲染
                table.render({
                    elem: '#pageTable',
                    height: 'full-10',
                    id: 'pageTable',
                    url: "/sys.menu/getabnormal",
                    toolbar: '#toolbarDemo',
                    defaultToolbar: ['filter'],
                    height:'full-40',
                    cols: [[
                        { type: 'checkbox'},
                        { type: 'numbers', title: '序号' },
                        { field: 'name', title: '名称', width: 150},
                        { field: 'node', title: '节点', width: 300 },
                        { field: 'menu_id', title: '菜单ID', align: 'center', width: 160 },
                        { field: 'p_menu_id', title: '菜单父ID', align: 'center', width: 150 },
                        {
                            field: 'menu_type', title: '类型', align: 'center', width: 100, templet: function (d) {
                                str = "";
                                switch (d.menu_type) {
                                    case 1:
                                        str = "父菜单";
                                        break;
                                    case 2:
                                        str = "子菜单";
                                        break;
                                    case 3:
                                        str = "按钮";
                                        break;
                                    case 4:
                                        str = "接口";
                                        break;
                                    case 5:
                                        str = "系统";
                                        break;
                                    default:
                                        str = "无";
                                        break;
                                }
                                return str;
                            }
                        },
                        { field: 'is_menu', title: '是否菜单', align: 'center', width: 110, templet: '#is_menu_td' },
                        { field: 'is_sys', title: '保留否', align: 'center', width: 120, templet: '#is_sys_td' },
                        { field: 'status', title: '启/禁用', align: 'center', width: 120, templet: '#status_td' }
                    ]]
                });

                form.on('switch(is_sys)', function (obj) {
                    var othat = $(obj.othis);
                    $.post("/sys.menu/updatefield", { id: obj.value, field: 'is_sys', value: obj.elem.checked ? 1 : 0 }, function (res) {
                        layer.tips(res.msg, othat[0], { tips: 4 });
                    });
                });

                form.on('switch(status)', function (obj) {
                    var othat = $(obj.othis);
                    $.post("/sys.menu/updatefield", { id: obj.value, field: 'status', value: obj.elem.checked ? 1 : 2 }, function (res) {
                        layer.tips(res.msg, othat[0], { tips: 4 });
                    });
                });

                // 工具栏事件
                table.on('toolbar(pageTable)', function (obj) {
                    var id = obj.config.id;
                    var checkStatus = table.checkStatus(id);
                    var data = checkStatus.data;
                    var othis = lay(this);
                    switch (obj.event) {
                        case 'getCheckStatus1':
                            checkfun('status', data, 1);
                            break;
                        case 'getCheckStatus2':
                            checkfun('status', data, 2);
                            break;
                        case 'getCheckIsSys1':
                            checkfun('is_sys', data, 1);
                            break;
                        case 'getCheckIsSys2':
                            checkfun('is_sys', data, 0);
                            break;
                    };
                });

                function checkfun(field, d, val) {
                    var ids = '';
                    $.each(d, function (i, obj) {
                        ids += obj.id + ',';
                    });
                    ids = ids.substring(0, ids.length - 1);
                    console.log(ids);
                    var constr = '';
                    if (field == 'status') {
                        if (val == 1) {
                            constr = '确认批量启用吗？';
                        } else if (val == 2) {
                            constr = '确认批量禁用吗？';
                        }
                    } else if (field == 'is_sys') {
                        if (val == 1) {
                            constr = '确认批量保留吗？';
                        } else if (val == 0) {
                            constr = '确认批量废弃吗？';
                        }
                    }
                    layer.confirm(constr, {
                        title: '确认操作',
                        btn: ['确认', '取消']
                    }, function () {
                        $.post('/sys.menu/checkfun', { id: ids, field: field,value:val }, function (res) {
                            res.status && table.reloadData('pageTable');
                            layer.msg(res.msg);
                        });
                    });
                }

            });
        });
    </script>
    <script type="text/html" id="is_sys_td">
        <input type="checkbox" name="is_sys" value="{{d.id}}" lay-skin="switch" lay-text="保留|废弃" lay-filter="is_sys" {{ d.is_sys == 1 ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="status_td">
        <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="is_menu_td">
        <i class="fa {{ d.is_menu==1 ? 'fa-toggle-on' : 'fa-toggle-off' }}"></i>
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-group">
            <a class="layui-btn layui-btn-sm layui-bg-blue" lay-event="getCheckStatus1"><i class="layui-icon layui-icon-edit"></i>批量启用</a>
            <a class="layui-btn layui-btn-sm layui-bg-red" lay-event="getCheckStatus2"><i class="layui-icon layui-icon-edit"></i>批量禁用</a>
            <a class="layui-btn layui-btn-sm layui-bg-blue" lay-event="getCheckIsSys1"><i class="layui-icon layui-icon-edit"></i>批量保留</a>
            <a class="layui-btn layui-btn-sm layui-bg-red" lay-event="getCheckIsSys2"><i class="layui-icon layui-icon-edit"></i>批量废弃</a>
        </div>
    </script>
</body>

</html>